var $ = require('../../lib/jquery');
var util = require('./common/util');
var nav = require('./common/nav');
var template = require('../tpl/template');
var _header = require('./common/header');
var minHeight = require('./common/minHeight');
minHeight.init();
var _nav = new nav();
var header = new _header();
var jhsy={
   page: 1,
    maxpage: null,
    init:function(){
      this.getList();
      this.bindevent();
    },
    getList:function(){
      var _this=this;
       util.fetch('/api/make/queryHospital?', {
         currentPage: _this.page,
        pageSize: 10,
        hospital_type: _this.hospital_type || '',
        hospital_level: '',
        dept_name: '计划生育专业',
       }).then(function (res) {
            var data = res.data
            _this.maxpage = data.totalPageSize;
             _this.render(data);
       })
    },
    bindevent:function(){
      $('.js_tab').on('click',function(){
          $('.js_tab').removeClass('tabColor');
          $(this).addClass('tabColor')
      })
      $('.js_changepage_add').on('click', function () {
        if (_this.page < _this.maxpage) {
          _this.page++
          _this.getList();
        }
      })
      $('.js_changepage_reduce').on('click', function () {
        if (_this.page > 1) {
          _this.page--;
          _this.getList();
        }
      })
    },
    render: function (data) {
      var tpl = template('map_list', {
        data: data.data
      })
      $('.js_doctor_list').html(tpl);
      if (this.maxpage <= 1) {
        $('.js_btns').addClass('hide')
      } else {
        $('.js_num_wrap').html(this.page + '/' + this.maxpage)
        $('.js_btns').removeClass('hide');
        if (this.page == 1) {
          $('.js_btns .js_changepage_reduce').removeClass('blue')
          $('.js_btns .js_changepage_add').addClass('blue')
        } else if (this.page < this.maxpage) {
          $('.js_btns .js_changepage_reduce').addClass('blue')
          $('.js_btns .js_changepage_add').addClass('blue')
        } else if (this.page == this.maxpage) {
          $('.js_btns .js_changepage_reduce').addClass('blue')
          $('.js_btns .js_changepage_add').removeClass('blue')
        } else {
          $('.js_btns .js_changepage_add').addClass('blue')
        }
      }
      $('.js_doc').off('click').on('click', function () {
        let hospital_id = $(this).data().id;
        let name = $(this).data().name;
        location.href = "./yuyue.html?deptid=1&hospital_id="+hospital_id+"&categoryId=2&name=计划生育专业"
      })
    },
  
}
jhsy.init()